/**
 * Main program package.
 */
package fr.umlv.m2.ig.main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.Timer;

import org.xml.sax.SAXException;

import fr.umlv.m2.ig.model.BeauheurModelImpl;
import fr.umlv.m2.ig.model.Train;
import fr.umlv.m2.ig.view.SubwayMapView;

/**
 * This class defines the main class of the program.
 * 
 * @author Gambouele Bertrand.
 * @author Viravout Alexandre.
 */
public class JacquesBeauheurTest {

	/**
	 * Main function : entry point of the program.
	 * @param args program arguments.
	 */
	public static void main(String[] args) {

		BeauheurModelImpl tmpModel = null;
		SubwayMapView mapView = null;
		final int refresh = 60;
		
		try {
			tmpModel = new BeauheurModelImpl(refresh);
			mapView = new SubwayMapView(tmpModel);
		} catch (SAXException e) {
			System.out.println("An error occured. Program will stop ...");
			e.printStackTrace();
			System.exit(1);
		} catch (IOException e) {
			System.out.println("An I/O error occured. Program will stop ...");
			e.printStackTrace();
			System.exit(1);
		}
		
		final BeauheurModelImpl model = tmpModel;
		
		final JFrame frame = new JFrame("Beauheur");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		final JLayeredPane mapPane = mapView.getPanel();
		frame.getContentPane().add(mapPane);
		frame.pack();
		frame.setResizable(false);
		frame.setVisible(true);
		
		// TODO A virer
		new Timer(
				7000,
				new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						Train train = new Train("1S00"+System.nanoTime(), "1", "La Defense", "Chateau de Vincennes", "La Defense");
						model.addTrain(train);
						train = new Train("1S00"+System.nanoTime(), "1", "Chateau de Vincennes", "La Defense", "Chateau de Vincennes");
						model.addTrain(train);
						
						train = new Train("2S00"+System.nanoTime(), "2", "Nation", "Porte Dauphine", "Nation");
						model.addTrain(train);
						train = new Train("2S00"+System.nanoTime(), "2", "Porte Dauphine", "Nation", "Porte Dauphine");
						model.addTrain(train);
						
						train = new Train("3S00"+System.nanoTime(), "3", "Gallieni", "Pont de Levallois - Becon", "Gallieni");
						model.addTrain(train);
						train = new Train("3S00"+System.nanoTime(), "3", "Pont de Levallois - Becon", "Gallieni", "Pont de Levallois - Becon");
						model.addTrain(train);
						
						train = new Train("3bS00"+System.nanoTime(), "3bis", "Gambetta", "Porte des Lilas", "Gambetta");
						model.addTrain(train);
						train = new Train("3bS00"+System.nanoTime(), "3bis", "Porte des Lilas", "Gambetta", "Porte des Lilas");
						model.addTrain(train);
						
						train = new Train("4S00"+System.nanoTime(), "4", "Porte de Clignancourt", "Porte d'Orleans", "Porte de Clignancourt");
						model.addTrain(train);
						train = new Train("4S00"+System.nanoTime(), "4", "Porte d'Orleans", "Porte de Clignancourt", "Porte d'Orleans");
						model.addTrain(train);
						
						train = new Train("5S00"+System.nanoTime(), "5", "Place d'Italie", "Bobigny - Pablo Picasso", "Place d'Italie");
						model.addTrain(train);
						train = new Train("5S00"+System.nanoTime(), "5", "Bobigny - Pablo Picasso", "Place d'Italie", "Bobigny - Pablo Picasso");
						model.addTrain(train);
						
						train = new Train("6S00"+System.nanoTime(), "6", "Charles de Gaulle - Etoile", "Nation", "Charles de Gaulle - Etoile");
						model.addTrain(train);
						train = new Train("6S00"+System.nanoTime(), "6", "Nation", "Charles de Gaulle - Etoile", "Nation");
						model.addTrain(train);
						
						train = new Train("7S00"+System.nanoTime(), "7", "La Courneuve - 8 Mai 1945", "Mairie d'Ivry", "La Courneuve - 8 Mai 1945");
						model.addTrain(train);
						train = new Train("7S00"+System.nanoTime(), "7", "Mairie d'Ivry", "La Courneuve - 8 Mai 1945", "Mairie d'Ivry");
						model.addTrain(train);
						train = new Train("7S00"+System.nanoTime(), "7", "Villejuif - Louis Aragon", "La Courneuve - 8 Mai 1945", "Villejuif - Louis Aragon");
						model.addTrain(train);
						train = new Train("7S00"+System.nanoTime(), "7", "La Courneuve - 8 Mai 1945", "Villejuif - Louis Aragon", "La Courneuve - 8 Mai 1945");
						model.addTrain(train);
						
						train = new Train("7bS00"+System.nanoTime(), "7bis", "Louis Blanc", "Pre-Saint-Gervais", "Louis Blanc");
						model.addTrain(train);
						train = new Train("7bS00"+System.nanoTime(), "7bis", "Pre-Saint-Gervais", "Louis Blanc", "Pre-Saint-Gervais");
						model.addTrain(train);
						
						train = new Train("8S00"+System.nanoTime(), "8", "Balard", "Creteil - Prefecture", "Balard");
						model.addTrain(train);
						train = new Train("8S00"+System.nanoTime(), "8", "Creteil - Prefecture", "Balard", "Creteil - Prefecture");
						model.addTrain(train);
						
						train = new Train("9S00"+System.nanoTime(), "9", "Mairie de Montreuil", "Pont de Sevres", "Mairie de Montreuil");
						model.addTrain(train);
						train = new Train("9S00"+System.nanoTime(), "9", "Pont de Sevres", "Mairie de Montreuil", "Pont de Sevres");
						model.addTrain(train);
						
						train = new Train("10S00"+System.nanoTime(), "10", "Boulogne - Pont de Staint-Could", "Gare d'Austerlitz", "Boulogne - Pont de Staint-Could");
						model.addTrain(train);
						train = new Train("10S00"+System.nanoTime(), "10", "Gare d'Austerlitz", "Boulogne - Pont de Staint-Could", "Gare d'Austerlitz");
						model.addTrain(train);
						
						train = new Train("11S00"+System.nanoTime(), "11", "Chatelet", "Mairie des Lilas", "Chatelet");
						model.addTrain(train);
						train = new Train("11S00"+System.nanoTime(), "11", "Mairie des Lilas", "Chatelet", "Mairie des Lilas");
						model.addTrain(train);
						
						train = new Train("12S00"+System.nanoTime(), "12", "Porte de la Chapelle", "Mairie d'Issy", "Porte de la Chapelle");
						model.addTrain(train);
						train = new Train("12S00"+System.nanoTime(), "12", "Mairie d'Issy", "Porte de la Chapelle", "Mairie d'Issy");
						model.addTrain(train);

						train = new Train("13S00"+System.nanoTime(), "13", "Chatillon - Montrouge", "Asnieres - Gennevilliers - Les Courtilles", "Chatillon - Montrouge");
						model.addTrain(train);
						train = new Train("13S00"+System.nanoTime(), "13", "Asnieres - Gennevilliers - Les Courtilles", "Chatillon - Montrouge", "Asnieres - Gennevilliers - Les Courtilles");
						model.addTrain(train);
						train = new Train("13S00"+System.nanoTime(), "13", "Chatillon - Montrouge", "Saint-Denis Universite", "Chatillon - Montrouge");
						model.addTrain(train);
						train = new Train("13S00"+System.nanoTime(), "13", "Saint-Denis Universite", "Chatillon - Montrouge", "Saint-Denis Universite");
						model.addTrain(train);
						
						train = new Train("14S00"+System.nanoTime(), "14", "Olympiades", "Saint-Lazare", "Olympiades");
						model.addTrain(train);
						train = new Train("14S00"+System.nanoTime(), "14", "Saint-Lazare", "Olympiades", "Saint-Lazare");
						model.addTrain(train);
					}
				}).start();
		
		// TODO Fin de a virer
		
		Timer timer = new Timer(refresh, new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				model.moveTrains();
			}
		});
		
		timer.start();
	}
	
}


